<?php #//AJAX PHP PENNY AUCTION v.1.1

#///////////////////////////////////////////////////////////
#//  COPYRIGHT 2009 Aaron Helmlinger ALL RIGHTS RESERVED  //
#///////////////////////////////////////////////////////////


include "./includes/config.inc.php";



    
    

#///////////////////////////////////////////////////////
#// Get Auto Bidder Settings
#///////////////////////////////////////////////////////
              
$query_settings = "select * from PHPAUCTIONXL_proxybid_settings where id='1'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $activated = mysql_result($query_settings2,0,"activated");

$query_settings3 = "select * from PHPAUCTIONXL_version_1_4 where id='1'";
                             $query_settings4 =  mysql_query ($query_settings3);
                                $autobidder_instant_death = mysql_result($query_settings4,0,"autobidder_instant_death");
                                $autobidder_activation_seconds = mysql_result($query_settings4,0,"autobidder_activation_seconds"); 
 
                       $query = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_version_1_3 WHERE id='1'"));
  
   $admin_daily_win_limits = $query['daily_win_limits'];
 $admin_weekly_win_limits = $query['weekly_win_limits'];
   $admin_monthly_win_limits = $query['monthly_win_limits'];           

#///////////////////////////////////////////////////////
#// Activate Auto Bidder
#///////////////////////////////////////////////////////

if ($activated == 1){



if ( $autobidder_instant_death == 0 ) { 
                                
       $cron = 0;
    while($cron < 20) {
    
    
  
#///////////////////////////////////////////////////////
#// Get Current Time
#///////////////////////////////////////////////////////

   $TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));

$date_time_now = date("YmdHis",$TIME);
$NOW = $date_time_now;
  
         $iloop = 0;

while($iloop < 10 ) {  

#///////////////////////////////////////////////////////
#// GET ACTIVE AUCTIONS FROM DATABASE 
#///////////////////////////////////////////////////////

$query = "select * from PHPAUCTIONXL_auctions
         WHERE closed='0' AND
         suspended='0' AND ";
         $query .= "starts<=".$NOW."
         order by id LIMIT 0,50";
$result = mysql_query($query);
$num_auction888 = mysql_num_rows($result);

$i = 0;


 // echo $num_auction;

while($i < $num_auction888) {


#///////////////////////////////////////////////////////
#// SET VARIABLE FOR ITEM TO BID ON 
#///////////////////////////////////////////////////////
      
      $title	= mysql_result($result,$i,"title");
	$id	= mysql_result($result,$i,"id");
	 $starts 	= mysql_result($result,$i,"starts");
  $ends 	= mysql_result($result,$i,"ends");
  $increment = mysql_result($result,$i,"increment");
  $high_bidder 	= mysql_result($result,$i,"current_high_bidder");
	$current_bid 	= mysql_result($result,$i,"current_bid");
   $closed 	= mysql_result($result,$i,"closed");
	  $unique1 	= mysql_result($result,$i,"unique1");
     $unique2 	= mysql_result($result,$i,"unique2");
       $reserve 	= mysql_result($result,$i,"reserve_price");
           $bid_credits_reqd1 = mysql_result($result,$i,"bid_credits_reqd");
             $item_extend_activated = mysql_result($result,$i,"ae_activation");
  $item_extend_increment = mysql_result($result,$i,"ae_increment");

 $auction_id_index = $id;

#/////////////////////////////////////////////////////////////////////
#// CALCULATE SECONDS LEFT UNTIL AUCTION ENDS
#/////////////////////////////////////////////////////////////////////

$time_ends_seconds = substr ($ends, 0, 4); // Year
$time_ends_seconds .= "-";
$time_ends_seconds .= substr ($ends, 4, 2); // Month
$time_ends_seconds .= "-";
$time_ends_seconds .= substr ($ends, 6, 2); // Day
$time_ends_seconds .= " ";
$time_ends_seconds .= substr ($ends, 8, 2); // Hour
$time_ends_seconds .= ":";
$time_ends_seconds .= substr ($ends, 10, 2); // Minute
$time_ends_seconds .= ":";
$time_ends_seconds .= substr ($ends, 12, 2); // Second

$time_now_seconds = date("Y-m-d H:i:s",$TIME);
 

 
// convert to unix timestamps
$firstTime=strtotime($time_now_seconds);
$lastTime=strtotime($time_ends_seconds);

// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;



$time_end_difference_in_seconds = $timeDiff;
$seconds_until_auction_ends = $time_end_difference_in_seconds;





#///////////////////////////////////////////////////////
#// Get Auto Bidder Data Greater Than Current Bid
#///////////////////////////////////////////////////////


 if ( $time_end_difference_in_seconds < $autobidder_activation_seconds ) {

 $num_proxybids = 0;

$query_proxybids = "select * from PHPAUCTIONXL_proxybid WHERE itemid='$id' AND bid > '$current_bid' AND startbid <= '$current_bid' AND proxybidqty > 0 ORDER BY bid ASC";
$result_proxybids = mysql_query($query_proxybids);


$num_proxybids = mysql_num_rows($result_proxybids);



 if ( $num_proxybids > 0 ) {         
        
    //    echo $num_proxybids;
     //     echo "<BR><BR>";
        
#///////////////////////////////////////////////////////
#// Select Lowest Maximum Bid Auto Bidder User
#///////////////////////////////////////////////////////

$ii = 0;



//$userid	= mysql_result($result_proxybids,$ii,"userid");
  //  $proxybid	= mysql_result($result_proxybids,$ii,"bid");
  //  $proxybidqty	= mysql_result($result_proxybids,$ii,"proxybidqty");
          
      
   $going_to_bid = 0;         
    
while( $ii < $num_proxybids ) {

if ( $going_to_bid < 1 )  {

    $userid	= mysql_result($result_proxybids,$ii,"userid");
    $proxybid	= mysql_result($result_proxybids,$ii,"bid");
    $proxystartbid	= mysql_result($result_proxybids,$ii,"bidstart");
    $proxybidqty	= mysql_result($result_proxybids,$ii,"proxybidqty");

      // echo $userid;
      // echo $proxybid;
      // echo $proxybidqty;   


#///////////////////////////////////////////////////////
#// Check If Current Bidder
#///////////////////////////////////////////////////////

  // if ( $proxybidqty > 0 ) {  

$query_user = mysql_fetch_array(mysql_query("SELECT nick, bids_remaining FROM PHPAUCTIONXL_users WHERE id='$userid'"));
   $username = $query_user['nick'];
   $bids_remaining = $query_user['bids_remaining'];
   
  /* echo "<BR>";
   echo $ii;
   echo "-----";
   echo $username;
   echo "-----";
   echo $bids_remaining;
   echo "-----";
   echo $high_bidder;
   echo "-----";
   echo $id;
   echo "<BR>";*/  
  
   
   
  // exit;
   
   
      
   
   
   
     	// CREATE WIN LIMIT DATES

    $daylimitdatestart = substr ($NOW, 0, 8);
    $daylimitdatestart .= "000000";
         // echo $daylimitdatestart."<BR>";

    $TIMEdaylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+1,date("Y"));

$NOWdaylimitdateend = date("YmdHis",$TIMEdaylimitdateend);

     $daylimitdateend = substr ($NOWdaylimitdateend, 0, 8);
    $daylimitdateend .= "000000";
          // echo $daylimitdateend."<BR>";
         $monthlylimitdatestart = substr ($NOW, 0, 6);
    $monthlylimitdatestart .= "01000000"; 
           // echo $monthlylimitdatestart."<BR>";
    
    $TIMEmonthlylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m")+1, date("d"),date("Y"));

$NOWmonthlylimitdateend = date("YmdHis",$TIMEmonthlylimitdateend);

     $monthlylimitdateend = substr ($NOWmonthlylimitdateend, 0, 6);
    $monthlylimitdateend .= "01000000";
                    // echo $monthlylimitdateend."<BR>";
    $jd=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$text_day = (jddayofweek($jd,1));

          //   echo $text_day;
    if ( $text_day == "Monday" ) {
        $day_correct_backwards = -1;
        $day_correct_forwards = 6;
    }  
    if ( $text_day == "Tuesday" ) {
        $day_correct_backwards = -2;
        $day_correct_forwards =5;
    }
    if ( $text_day == "Wednesday" ) {
        $day_correct_backwards = -3;
        $day_correct_forwards = 4;
    }
        if ( $text_day == "Thursday" ) {
        $day_correct_backwards = -4;
        $day_correct_forwards = 3;
    }
    if ( $text_day == "Friday" ) {
        $day_correct_backwards = -5;
        $day_correct_forwards =2;
    }
    if ( $text_day == "Saturday" ) {
        $day_correct_backwards = -6;
        $day_correct_forwards =1;
    }
    if ( $text_day == "Sunday" ) {
        $day_correct_backwards = 0;
        $day_correct_forwards = 7;
    }
    
        //  echo $day_correct_backwards;
      //  echo $day_correct_forwards;
$TIMEweeklylimitdatestart = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+$day_correct_backwards,date("Y"));

$NOWweeklylimitdatestart = date("YmdHis",$TIMEweeklylimitdatestart);
    
        $weeklylimitdatestart = substr ($NOWweeklylimitdatestart, 0, 8);
    $weeklylimitdatestart .= "000000";

        // echo $weeklylimitdatestart."<BR>";
  
  $TIMEweeklylimitdateend = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d")+$day_correct_forwards,date("Y"));

$NOWweeklylimitdateend = date("YmdHis",$TIMEweeklylimitdateend);
    
        $weeklylimitdateend = substr ($NOWweeklylimitdateend, 0, 8);
    $weeklylimitdateend .= "000000";
    //echo $weeklylimitdateend."<BR>";

// Query Auctions For Limits  
  
  
    $querydaily = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$Winner[nick]' AND closed=1 AND
         ends > $daylimitdatestart AND
         ends < $daylimitdateend";
$resultdaily = mysql_query($querydaily);
$user_daily_wins = mysql_num_rows($resultdaily);

if ( $user_daily_wins < $admin_daily_win_limits ) {

      $going_to_bid = 1;
}


       
          $queryweekly = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$Winner[nick]' AND 
         closed=1 AND
         ends > $weeklylimitdatestart AND
         ends < $weeklylimitdateend";
$resultweekly = mysql_query($queryweekly);
$user_weekly_wins = mysql_num_rows($resultweekly);


if ( $user_weekly_wins < $admin_weekly_win_limits ) {
    $going_to_bid = 1;
}


  			
				
				




     $querymonthly = "select * from PHPAUCTIONXL_auctions
         WHERE current_high_bidder='$Winner[nick]' AND 
         closed=1 AND
         ends > $monthlylimitdatestart AND
         ends < $monthlylimitdateend";
$resultmonthly= mysql_query($querymonthly);
$user_monthly_wins = mysql_num_rows($resultmonthly);


    if ( $user_monthly_wins < $admin_monthly_win_limits ) {

          $going_to_bid = 1;

}			
					
			
					
   

   
   // echo "-----------------------------------------------";
   
   
  //   }
   
   
   
   
   
   
   
    
   }
   
  $ii++; } // WHILE $GOING_TO_BID != 1
  
  }
  
#///////////////////////////////////////////////////////
#// Place Auto Bidder Bid
#///////////////////////////////////////////////////////


 if ( $going_to_bid == 1 ) {

 // echo $going_to_bid;
//  echo $accounttype;
  
$increment = $increment;

$current_bid = $current_bid;

$high_bid = $increment + $current_bid;

$proxybidqty--;

$bids_remaining2 = $bids_remaining - $bid_credits_reqd1;

//echo $high_bid;

$query1 = "INSERT INTO PHPAUCTIONXL_bids VALUES";

$query1 .= "(NULL";
$query1 .= ",";
$query1 .= $id;
$query1 .= ",";
$query1 .= $userid;
$query1 .= ",";
$query1 .= $high_bid;
$query1 .= ",";
$query1 .= $NOW;
$query1 .= ",";
$query1 .= "1";
$query1 .= ",";
$query1 .= "'";
$query1 .= $username;
$query1 .= "'";
$query1 .= ",";
$query1 .= "'";
$query1 .= proxy;
$query1 .= "'";
$query1 .= ")";
     
   // echo $query1;
    //echo "<BR>";       
mysql_query($query1);


         $query12 = "INSERT INTO PHPAUCTIONXL_bids2 VALUES";

$query12 .= "(NULL";
$query12 .= ",";
$query12 .= $id;
$query12 .= ",";
$query12 .= $userid;
$query12 .= ",";
$query12 .= $high_bid;
$query12 .= ",";
$query12 .= $NOW;
$query12 .= ",";
$query12 .= "1";
$query12 .= ",";
$query12 .= "'";
$query12 .= $username;
$query12 .= "'";
$query12 .= ",";
$query12 .= "'";
$query12 .= proxy;
$query12 .= "'";
$query12 .= ")";
     
   // echo $query12;
    //echo "<BR>";       
mysql_query($query12);
 
$query2="UPDATE PHPAUCTIONXL_auctions SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$id'";
   //echo $query2; 
   // echo "<BR>";
mysql_query($query2);


     $query212="UPDATE PHPAUCTIONXL_auctions2 SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$id'";
   //echo $query2; 
   // echo "<BR>";
mysql_query($query212);

$query25="UPDATE PHPAUCTIONXL_proxybid SET proxybidqty='$proxybidqty' WHERE userid='$userid' AND itemid='$id'";
   //echo $query25; 
   // echo "<BR>";
mysql_query($query25);
   
   
 $query24="UPDATE PHPAUCTIONXL_users SET bids_remaining='$bids_remaining2' WHERE id='$userid'";
   //echo $query24; 
   // echo "<BR>";
mysql_query($query24);  
   
   
   
       
 $auctionends = $ends;   
   
       $query435 = mysql_fetch_array(mysql_query("SELECT bid_credits_reqd,ends,ae_activation,ae_increment,time_increment,hard_reset FROM PHPAUCTIONXL_auctions WHERE id=$auction_id_index "));
  

 $auctionends = $query435['ends'];
  $item_extend_activated = $query435['ae_activation'];
  $item_extend_increment = $query435['ae_increment'];
  $bid_credits_reqd1 = $query435['bid_credits_reqd'];
     $hard_reset_check = $query435['hard_reset'];
  
  
  if ( $hard_reset_check == 0 ) {
  
  if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            $TIME_EXTEND = $EXTSETTINGS['timebefore'] + 10;
            
            if (($__END - $TIME) <= $TIME_EXTEND) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($EXTSETTINGS['extend'] + 3), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

            $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                
                            $query692 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query692);
            
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
                $TIME_EXTEND = $item_extend_activated + 10;
            if (($__END - $TIME) <= $TIME_EXTEND ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment + 3), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

       $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                
                    $query693 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query693);
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

                }
                
                
                
                
                
            if ( $hard_reset_check == 1 ) {
            
            
            
                 if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            $TIME_EXTEND = $EXTSETTINGS['timebefore'];
                     
                         $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $EXTSETTINGS['extend'] - $timeremaining22;
              
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

            $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                
                            $query692 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query692);
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
                $TIME_EXTEND = $item_extend_activated;
                          $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $item_extend_increment - $timeremaining22;
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

       $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                
                          $query693 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query693);
                
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }


   
                        
            
            
            
            }    
                
                
                
                
                
                
                
                
                
     $query99a = "select * from PHPAUCTIONXL_bids WHERE auction='$auction_id' ORDER BY id";
$result99a = mysql_query($query99a);
$num_auction3443 = mysql_num_rows($result99a);

if ( $num_auction3443 > 15 ) {

   $bidwhen1 	= mysql_result($result99a,2,"id");

    $removeold="DELETE from PHPAUCTIONXL_bids where id<'$bidwhen1' AND auction='$auction_id'";
mysql_query($removeold);

}               
          
   

   $going_to_bid = 0;
     
} // End Bid
} // TIME UNTIL END IS LESS THAN 30 SECONDS
$i++; //echo "end of script";
} // FOREACH LIVE AUCTION
 //echo "worked";
$iloop++;
} // iloop
//echo "worked";


        
       $cron++;  
       
       if ( $cron == 20 )
  
  {
    mysql_close($linktodatabase);
  exit;
    }
       
       sleep(3); 
               //  echo $cron;
               // echo "<BR>";
             
        



}
    }
    
    
    
    
    
if ( $autobidder_instant_death == 1 ) { 
                                
       $cron = 0;
    while($cron < 30) {    
    
    
                
#///////////////////////////////////////////////////////
#// Get Current Time
#///////////////////////////////////////////////////////

   $TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));

$date_time_now = date("YmdHis",$TIME);
$NOW = $date_time_now;

                                



#///////////////////////////////////////////////////////
#// Instant Death Loop
#///////////////////////////////////////////////////////

$iloop = 0;

while($iloop < 10 ) {    




#///////////////////////////////////////////////////////
#// GET ACTIVE AUCTIONS FROM DATABASE 
#///////////////////////////////////////////////////////

$query = "select * from PHPAUCTIONXL_auctions
         WHERE closed='0' AND
         suspended='0' AND ";
         $query .= "starts<=".$NOW."
         order by id LIMIT 0,50";
$result = mysql_query($query);
$num_auction2121 = mysql_num_rows($result);

$i = 0;


 // echo $num_auction;

while($i < $num_auction2121) {


#///////////////////////////////////////////////////////
#// SET VARIABLE FOR ITEM TO BID ON 
#///////////////////////////////////////////////////////
      
      $title	= mysql_result($result,$i,"title");
	$id	= mysql_result($result,$i,"id");
	 $starts 	= mysql_result($result,$i,"starts");
  $ends 	= mysql_result($result,$i,"ends");
  $increment = mysql_result($result,$i,"increment");
  $high_bidder 	= mysql_result($result,$i,"current_high_bidder");
	$current_bid 	= mysql_result($result,$i,"current_bid");
   $closed 	= mysql_result($result,$i,"closed");
	  $unique1 	= mysql_result($result,$i,"unique1");
     $unique2 	= mysql_result($result,$i,"unique2");
       $reserve 	= mysql_result($result,$i,"reserve_price");
           $bid_credits_reqd1 = mysql_result($result,$i,"bid_credits_reqd");
             $item_extend_activated = mysql_result($result,$i,"ae_activation");
  $item_extend_increment = mysql_result($result,$i,"ae_increment");

 $auction_id_index = $id;

#/////////////////////////////////////////////////////////////////////
#// CALCULATE SECONDS LEFT UNTIL AUCTION ENDS
#/////////////////////////////////////////////////////////////////////

$time_ends_seconds = substr ($ends, 0, 4); // Year
$time_ends_seconds .= "-";
$time_ends_seconds .= substr ($ends, 4, 2); // Month
$time_ends_seconds .= "-";
$time_ends_seconds .= substr ($ends, 6, 2); // Day
$time_ends_seconds .= " ";
$time_ends_seconds .= substr ($ends, 8, 2); // Hour
$time_ends_seconds .= ":";
$time_ends_seconds .= substr ($ends, 10, 2); // Minute
$time_ends_seconds .= ":";
$time_ends_seconds .= substr ($ends, 12, 2); // Second

$time_now_seconds = date("Y-m-d H:i:s",$TIME);
 

 
// convert to unix timestamps
$firstTime=strtotime($time_now_seconds);
$lastTime=strtotime($time_ends_seconds);

// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;



$time_end_difference_in_seconds = $timeDiff;
$seconds_until_auction_ends = $time_end_difference_in_seconds;





#///////////////////////////////////////////////////////
#// Get Auto Bidder Data Greater Than Current Bid
#///////////////////////////////////////////////////////

 if ( $time_end_difference_in_seconds < 999999999999 ) {

 $num_proxybids = 0;

  $query_proxybids = "select * from PHPAUCTIONXL_proxybid WHERE itemid='$id' AND bid > '$current_bid' AND proxybidqty > 0 ORDER BY bid ASC";
$result_proxybids = mysql_query($query_proxybids);


$num_proxybids = mysql_num_rows($result_proxybids);



 if ( $num_proxybids > 0 ) {         
        
    //    echo $num_proxybids;
     //     echo "<BR><BR>";
        
#///////////////////////////////////////////////////////
#// Select Lowest Maximum Bid Auto Bidder User
#///////////////////////////////////////////////////////

$ii = 0;



//$userid	= mysql_result($result_proxybids,$ii,"userid");
  //  $proxybid	= mysql_result($result_proxybids,$ii,"bid");
  //  $proxybidqty	= mysql_result($result_proxybids,$ii,"proxybidqty");
          
      
   $going_to_bid = 0;         
    
while( $ii < $num_proxybids ) {

if ( $going_to_bid < 1 )  {

    $userid	= mysql_result($result_proxybids,$ii,"userid");
    $proxybid	= mysql_result($result_proxybids,$ii,"bid");
    $proxybidqty	= mysql_result($result_proxybids,$ii,"proxybidqty");

      // echo $userid;
      // echo $proxybid;
      // echo $proxybidqty;   


#///////////////////////////////////////////////////////
#// Check If Current Bidder
#///////////////////////////////////////////////////////

  // if ( $proxybidqty > 0 ) {  

$query_user = mysql_fetch_array(mysql_query("SELECT nick, bids_remaining FROM PHPAUCTIONXL_users WHERE id='$userid'"));
   $username = $query_user['nick'];
   $bids_remaining = $query_user['bids_remaining'];
   
   /*echo "<BR>";
   echo $ii;
   echo "-----";
   echo $username;
   echo "-----";
   echo $bids_remaining;
   echo "-----";
   echo $high_bidder;
   echo "-----";
   echo $id;
   echo "<BR>";  */
  
   
   
  // exit;
   
   
      
   if ( !($username==$high_bidder) && $bids_remaining > 0 ) {
   

   
  $going_to_bid = 1;
   
   // echo "-----------------------------------------------";
   
   
  //   }
   
   }   
   }
   
  $ii++; } // WHILE $GOING_TO_BID != 1
  
  }
  
#///////////////////////////////////////////////////////
#// Place Auto Bidder Bid
#///////////////////////////////////////////////////////


 if ( $going_to_bid == 1 ) {

 // echo $going_to_bid;
//  echo $accounttype;
  
$increment = $increment;

$current_bid = $current_bid;

$high_bid = $increment + $current_bid;

$proxybidqty--;

$bids_remaining2 = $bids_remaining - $bid_credits_reqd1;

//echo $high_bid;

$query1 = "INSERT INTO PHPAUCTIONXL_bids VALUES";

$query1 .= "(NULL";
$query1 .= ",";
$query1 .= $id;
$query1 .= ",";
$query1 .= $userid;
$query1 .= ",";
$query1 .= $high_bid;
$query1 .= ",";
$query1 .= $NOW;
$query1 .= ",";
$query1 .= "1";
$query1 .= ",";
$query1 .= "'";
$query1 .= $username;
$query1 .= "'";
$query1 .= ",";
$query1 .= "'";
$query1 .= proxy;
$query1 .= "'";
$query1 .= ")";
     
   // echo $query1;
    //echo "<BR>";       
mysql_query($query1);

        $query12 = "INSERT INTO PHPAUCTIONXL_bids2 VALUES";

$query12 .= "(NULL";
$query12 .= ",";
$query12 .= $id;
$query12 .= ",";
$query12 .= $userid;
$query12 .= ",";
$query12 .= $high_bid;
$query12 .= ",";
$query12 .= $NOW;
$query12 .= ",";
$query12 .= "1";
$query12 .= ",";
$query12 .= "'";
$query12 .= $username;
$query12 .= "'";
$query12 .= ",";
$query12 .= "'";
$query12 .= proxy;
$query12 .= "'";
$query12 .= ")";
     
   // echo $query12;
    //echo "<BR>";       
mysql_query($query12);
   
 
$query2="UPDATE PHPAUCTIONXL_auctions SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$id'";
   //echo $query2; 
   // echo "<BR>";
mysql_query($query2);

     $query212="UPDATE PHPAUCTIONXL_auctions2 SET current_high_bidder='$username', current_bid='$high_bid' WHERE id='$id'";
   //echo $query2; 
   // echo "<BR>";
mysql_query($query212);

$query25="UPDATE PHPAUCTIONXL_proxybid SET proxybidqty='$proxybidqty' WHERE userid='$userid' AND itemid='$id'";
   //echo $query25; 
   // echo "<BR>";
mysql_query($query25);
   
   
 $query24="UPDATE PHPAUCTIONXL_users SET bids_remaining='$bids_remaining2' WHERE id='$userid'";
   //echo $query24; 
   // echo "<BR>";
mysql_query($query24);  
   
   
   
       
 $auctionends = $ends;   
   
       $query435 = mysql_fetch_array(mysql_query("SELECT bid_credits_reqd,ends,ae_activation,ae_increment,time_increment FROM PHPAUCTIONXL_auctions WHERE id=$auction_id_index "));
  

 $auctionends = $query435['ends'];
  $item_extend_activated = $query435['ae_activation'];
  $item_extend_increment = $query435['ae_increment'];
  $bid_credits_reqd1 = $query435['bid_credits_reqd'];
       $hard_reset_check = $query435['hard_reset'];
  
  
  if ( $hard_reset_check == 0 ) {
  
  if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            $TIME_EXTEND = $EXTSETTINGS['timebefore'] + 10;
            
            if (($__END - $TIME) <= $TIME_EXTEND) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($EXTSETTINGS['extend'] + 3), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

            $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
            
                              $query692 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query692);
            
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
                $TIME_EXTEND = $item_extend_activated + 10;
            if (($__END - $TIME) <= $TIME_EXTEND ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment + 3), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

       $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                      $query693 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query693); 
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

                }
                
                
                
                
                
            if ( $hard_reset_check == 1 ) {
            
            
            
                 if ( $item_extend_activated == 0) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
        $EXTSETTINGS = mysql_fetch_array(mysql_query("SELECT * FROM PHPAUCTIONXL_auctionextension"));
        if ($EXTSETTINGS['status'] == 'enabled') {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
            $TIME_EXTEND = $EXTSETTINGS['timebefore'];
                     
                         $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $EXTSETTINGS['extend'] - $timeremaining22;
              
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

            $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                        $query692 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query692);
            
            
            
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }

         if ( $item_extend_activated > 0 ) {  
    /**
        * NOTE: AUCTION AUTOEXTENSION
        */
           if ( 1 == 1 ) {
          $__END = mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4));
            
                $TIME_EXTEND = $item_extend_activated;
                          $timeremaining22 = $__END - $TIME;
              $item_extend_increment1 = $item_extend_increment - $timeremaining22;
            if (($__END - $TIME) <= $TIME_EXTEND + 8 ) {
                $auctionends = date("YmdHis", mktime(substr($auctionends, 8, 2), substr($auctionends, 10, 2), substr($auctionends, 12, 2) + ($item_extend_increment1 + 8), substr($auctionends, 4, 2), substr($auctionends, 6, 2), substr($auctionends, 0, 4)));
           
            }

       $query69 = "UPDATE PHPAUCTIONXL_auctions set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query69);
                
                       $query693 = "UPDATE PHPAUCTIONXL_auctions2 set ends='$auctionends' WHERE id=$auction_id_index";
                mysql_query($query693);
                
                
             if (($__END - $TIME) <= 0 ) {
            
                    $closed = "1";
                    
                          }
                          
                          
        }
            }


   
                        
            
            
            
            }    
                
                        $query99a = "select * from PHPAUCTIONXL_bids WHERE auction='$auction_id' ORDER BY id";
$result99b = mysql_query($query99a);
$num_auction4231 = mysql_num_rows($result99b);

if ( $num_auction4231 > 15 ) {

   $bidwhen1 	= mysql_result($result99b,2,"id");

     $removeold="DELETE from PHPAUCTIONXL_bids where id<'$bidwhen1' AND auction='$auction_id'";
mysql_query($removeold);

}


   $going_to_bid = 0;
     
} // End Bid
} // TIME UNTIL END IS LESS THAN 30 SECONDS
$i++; //echo "end of script";
} // FOREACH LIVE AUCTION

//echo "worked";
$iloop++;
} // iloop



 //echo "worked";


        
       $cron++;  
       
       if ( $cron == 30 )
  
  {
  
    mysql_close($linktodatabase);
  exit;
    }
       
       sleep(2); 
               //  echo $cron;
               // echo "<BR>";
             
        



}
    }   
    
    
    
    
    
    
    
    
    
    
    
    
    
    

} // SCRIPT ACTIVATED



   ?>